#ifndef GAMEPLAY_H
#define GAMEPLAY_H

#include "qgraphicsitem.h"
#include "qgraphicsscene.h"
#include "qgraphicsview.h"
#include "qpushbutton.h"
#include "qtimer.h"
#include"character.h"
#include <QWidget>
#include<QKeyEvent>
#include<QList>
#include<QMessageBox>

class gamePlay:public QWidget
{
public:
    gamePlay(QWidget *parent = nullptr);

    void message(){
        this->close();
    }
public slots:

    void chtom(){
        temp.setPixmap(QPixmap("tomfly"));
        temp.setPos(100,100);
        speed=1;
    }
    void chjerry(){
        temp.setPixmap(QPixmap("jerryfly"));
        temp.setPos(100,100);
        speed=1;
    }

    void bgmove(){
        background1.moveBy(-speed,0);
        background2.moveBy(-speed,0);
        if(background1.x()<=-500){
            background1.setX(500);
        }
        if(background2.x()<=-500){
            background2.setX(500);
        }
    }

    // 槽函数，增加速度
    void increaseSpeed() {
        speed += 1; // 每次增加 1
        if (speed > 20) {
            speed = 20; // 最大速度限制为 20
        }
    }
public:
    QGraphicsScene  gamescene ;
    QGraphicsView  gameview;

    QGraphicsPixmapItem background1,background2;
    QGraphicsPixmapItem tom,jerry;
    character temp;

    QPushButton stop;

    int speed = 1; // 初始速度为 1

    QTimer speedTimer;

    //背景移动
    QTimer bgm;

    QTimer cmove;

    //角色移动
    void charactermove();


    //按键组合

    QList<int> mykeylist;

    //按键事件
    void keyPressEvent(QKeyEvent *event);

    void keyReleaseEvent(QKeyEvent *event);
private:
};

#endif // GAMEPLAY_H
